<template>
  <div class="app-container">
    <div class="app-container_conter">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px"
               style="display: flex;justify-content: space-between;align-items: flex-end">
        <div>
          <el-form-item label="职业" prop="industryId">
            <treeselect style="width: 220px" v-model="queryParams.industryId" :options="industryOptions"
                        :normalizer="normalizer" placeholder="请选择职业"/>
          </el-form-item>
          <el-form-item label="姓名" prop="name">
            <el-input
                v-model="queryParams.name"
                placeholder="请输入姓名"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="实际用工单位" prop="actualUnit" label-width="150">
            <el-input
                v-model="queryParams.actualUnit"
                placeholder="请输入实际用工"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="出险日期" prop="createTime" style="margin-bottom: 10px">
            <el-date-picker
                v-model="queryParams.createTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="被保险人" prop="userId">
            <el-select v-model="queryParams.userId" placeholder="请选择被保险人" clearable size="small">
              <el-option
                  v-for="item in insured"
                  :key="item.user_id"
                  :label="item.user_name"
                  :value="item.user_id"
              />
            </el-select>
          </el-form-item>
        </div>
        <!--      <el-form-item label="状态" prop="status">-->
        <!--        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">-->
        <!--          <el-option-->
        <!--            v-for="dict in statusOptions"-->
        <!--            :key="dict.dictValue"-->
        <!--            :label="dict.dictLabel"-->
        <!--            :value="dict.dictValue"-->
        <!--          />-->
        <!--        </el-select>-->
        <!--      </el-form-item>-->
        <div style="width: 150px">
        <el-form-item style="width: 150px;text-align: right;">
          <el-button type="primary" size="mini" @click="handleQuery">搜索</el-button>
          <el-button type="info" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
        </div>
      </el-form>
      <el-row style="margin-bottom: 10px">
        <el-col :span="1.5">
          <el-button
              type="primary"
              size="mini"
              @click="handleExport"
              v-hasPermi="['insurance:repordRecord:export']"
          >导出
          </el-button>
        </el-col>
        <!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
      </el-row>

      <el-table v-loading="loading" :data="repordRecordList" @selection-change="handleSelectionChange"
                :header-cell-style="tableHeaderColor">
        <el-table-column type="selection" width="55" align="center"/>
        <!--      <el-table-column label="主键" align="center" prop="id" />-->
        <el-table-column label="被保险人" align="center" prop="user_name"  min-width="100px"/>
        <el-table-column label="姓名" align="center" prop="name" min-width="100px"/>
        <el-table-column label="实际用工单位" align="center" prop="actual_unit" min-width="180px"/>
        <el-table-column label="劳动合同单位" align="center" prop="labor_unit" min-width="180px"/>
        <el-table-column label="业务来源单位" align="center" prop="business_unit" min-width="150px"/>
        <el-table-column label="事故发生时间" align="center" prop="accident_time" min-width="120px">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.accident_time, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <!--      <el-table-column label="工种" align="center" prop="industryId" />-->
        <el-table-column label="事情经过" align="center" prop="description" min-width="180px">
          <template slot-scope="scope">
            <div class="Multilines">
              <div class="Multiline">
                <label class="btn" @click="handDetails(scope.row)"><span style="color: #606266">...</span>更多</label>
                <span>{{ scope.row.description }}</span>
              </div>
            </div>

          </template>
        </el-table-column>
        <el-table-column label="工种名称" align="center" prop="industry_name" min-width="150px"/>
        <el-table-column label="预估金额" align="center" prop="estimate_money" min-width="100px"/>
        <el-table-column label="创建时间" align="center" prop="create_time" min-width="150px"/>
        <el-table-column label="更新时间" align="center" prop="update_time" min-width="150px"/>
        <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat"/>
        <el-table-column label="操作" align="center"  min-width="250px"
                         class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
                size="mini"
                type="text"
                v-hasPermi="['insurance:repordRecord:query']"
                @click="handDetails(scope.row)"
            >详情
            </el-button>
            <el-button
                size="mini"
                type="text"
                @click="handlereport(scope.row)"
                v-hasPermi="['insurance:repordRecord:review']"
                v-if="scope.row.status=='1' "
            >通过
            </el-button>

            <el-button
                size="mini"
                type="text"
                @click="handlerejection(scope.row)"
                v-hasPermi="['insurance:repordRecord:review']"
                v-if="scope.row.status=='1' "
            >拒绝
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination
        style="background: transparent"
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="拒绝原因" prop="reason">
          <el-input type="textarea" v-model="form.reason" placeholder="请输入拒绝原因"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('form')">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  exportRepordRecord1,
  listRepordRecord,
  delRepordRecord,
  get_base_industry,
  exportRepordRecord,
  review,
  listReportedAndData,
  listReportedAndData1
} from "@/api/insurance/repordRecord";
import {uploadTmage} from "@/api/base/template";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {listIndustry} from "@/api/insurance/industry";
import {seacond_admin} from "@/api/insurance/user";

export default {
  name: "RepordRecord",
  components: {
    Treeselect
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报案表格数据
      repordRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        user_id: '',
        pageNum: 1,
        pageSize: 10,
        name: null,
        actualUnit: null,
        laborUnit: null,
        businessUnit: null,
        accidentTime: null,
        industryId: null,
        description: null,
        industryName: null,
        estimateMoney: null,
        createTime: null,
        statuses: ['1'],
        userId: '',//被保险人id
      },
      // 表单参数
      form: {
        reason: '',//拒绝原因
        reportId: '',//报案id
        status: '3',//状态
      },
      statusOptions1: [],//字典状态
      // 表单校验
      rules: {
        reason: [
          {required: true, message: '拒绝原因不能为空', trigger: 'blur'},
        ]
      },
      // 职业分类树选项
      industryOptions: [],
      queryParams3: {
        user_id: '',
        role_id: '',
      },
      insured: [],//被保险人
      queryParams4: {
        ids: '',
        status: '1'
      }
    };
  },
  created() {
    this.queryParams.user_id = JSON.parse(localStorage.getItem('userInfo')).userId;
    var user = JSON.parse(localStorage.getItem('userInfo'));
    this.queryParams3.user_id = user.userId;

    if (user.roles.length != 0) {
      this.queryParams3.role_id = user.roles[0].roleId
    }
    seacond_admin(this.queryParams3).then(res => {
      this.insured = res.data;
      // console.log('被保险人数据',res)
    })
    this.getList();
    this.getDicts("report_status").then(response => {
      // console.log('response12',response)
      this.statusOptions = response.data;
    });
    this.getTreeselect();
  },
  methods: {
    /* 修改表头颜色 */
    tableHeaderColor({rowIndex}) {
      if (rowIndex === 0) {
        return 'background-color: #304156;color: #fff;font-weight: 400;font-family: Microsoft YaHei;'
      }
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      get_base_industry().then(response => {
        // console.log('response职业',response)
        this.industryOptions = [];
        const data = {id: 0, name: '顶级节点', children: []};
        data.children = this.handleTree(response.data, "id", "parent_id");
        this.industryOptions.push(data);
      })
      // listIndustry().then(response => {
      //   this.industryOptions = [];
      //   const data = {id: 0, name: '顶级节点', children: []};
      //   data.children = this.handleTree(response.data, "id", "parentId");
      //   this.industryOptions.push(data);
      //   console.log('工种名称', response);
      //   console.log('industryOptions', this.industryOptions);
      // });
    },
    //提交审核
    submitForm(form) {
      // console.log('form',this.form)
      this.form.status = '2'
      this.$refs[form].validate((valid) => {
        if (valid) {
          review(this.form).then(res => {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.open = false
            this.getList();
            // console.log('审核',res)
          })
        }
      });
    },
    //查询报案详情
    handDetails(row) {
      this.$router.push({
        path: '/business/reportAudit/details',
        query: {
          id: row.id,
          insure_no:row.insure_no,
          user_name:row.user_name
        }
      })
    },
    /** 转换职业分类数据结构 */
    normalizer(node) {
      // console.log('node',node)
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      };
    },
    /** 查询报案列表 */
    getList() {
      // console.log('审核查询23',this.queryParams)

      this.loading = true;
      listReportedAndData1(this.queryParams).then(response => {
        // console.log('response',response)
        this.repordRecordList = response.data.rows;
        // for (var i=0;i<this.repordRecordList.length;i++){
        //   this.repordRecordList[i].userPicture.idCard=JSON.parse(this.repordRecordList[i].userPicture.idCard)
        //   this.repordRecordList[i].userPicture.medicalHistory=JSON.parse(this.repordRecordList[i].userPicture.medicalHistory)
        //   this.repordRecordList[i].userPicture.medicalInvoice=JSON.parse(this.repordRecordList[i].userPicture.medicalInvoice)
        //   this.repordRecordList[i].userPicture.medications=JSON.parse(this.repordRecordList[i].userPicture.medications)
        //   this.repordRecordList[i].userPicture.other=JSON.parse(this.repordRecordList[i].userPicture.other)
        //   this.repordRecordList[i].userPicture.hospitalized=JSON.parse(this.repordRecordList[i].userPicture.hospitalized)
        // }
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length;
      if (this.repordRecordList.length == selection.length) {
        this.queryParams4.ids = '';
      } else {
        this.queryParams4.ids = this.ids;
      }
    },
    //审核
    handlereport(row) {
      this.form.reportId = row.id
      // console.log('form',this.form)
      var that = this
      this.form.status = '3'
      this.$confirm('是否确认审核通过', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        review(that.form).then(res => {
          // console.log('审核',res)
          that.$message({
            message: res.msg,
            type: 'success'
          })
          that.getList();
        })
      }).then(response => {

      })
    },
    /** 拒绝审核 */
    handlerejection(row) {
      this.form.reportId = row.id
      this.open = true;

    },
    /** 导出按钮操作 */
    handleExport() {
      var that = this;
      // const queryParams = this.queryParams;
      this.$confirm('是否确认导出报案审核数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        const loading = that.$loading({
          lock: true,
          text: '请耐心等待正在导出数据...',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        exportRepordRecord1(that.queryParams4).then(response => {
          loading.close();
          let link = document.createElement('a'); // 创建a标签
          link.style.display = 'none';
          let objectUrl = response.data;
          link.href = objectUrl;
          link.click();
          that.msgSuccess(response.msg);
          // console.log('response24',response)
        });
      }).then(response => {

      })
    }
  }
};
</script>
<style scoped lang="scss">
.Multilines {
  display: flex;
  .Multiline::before {
    //display: flex;
    content: '';
    //justify-content: space-between;
    float: right;
    height: 100%;
    margin-bottom: -20px;

  }

  .Multiline {
    //display: -webkit-box;
    max-height: 60px;
    line-height: 20px;
    //background: pink;
    overflow: hidden;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;

    .btn {

      color: #0793FF;
      float: right;
      clear: both;
      margin-right: 8px;
    }

  }

}

</style>


